<template>
	<view class="loginBox pT25 pL15 pR15">
		<view class="font24 bold pL">请选择身份</view>
		<view class="mT10 u-9 font14">可以精准推送您需要的用工信息</view>
		<view class="bfRa pL15 pR15 pT15 pB15 flex alg-center jst-between mT10" @click="personChange">
			<view class="flex alg-center">
				<u-image :width="54" :height="54" :src="resources.job.gr"></u-image>
				<view class="mL10">
					<view class="font16">个人角色</view>
					<view class="font12 u-9 mT5">换成个人招工角色</view>
				</view>
			</view>
			<u-image :width="34" :height="34" :src="resources.job.cirMore"></u-image>
		</view>
		<view class="bfRa pL15 pR15 pT15 pB15 flex alg-center jst-between mT20"
			@click="companyChange">
			<view class="flex alg-center">
				<u-image :width="54" :height="54" :src="resources.job.qy"></u-image>
				<view class="mL10">
					<view class="font16">企业角色</view>
					<view class="font12 u-9 mT5">换成企业招工角色</view>
				</view>
			</view>
			<u-image :width="34" :height="34" :src="resources.job.cirMore"></u-image>
		</view>
		<xfTipModal ref="tipModal"></xfTipModal>
	</view>
</template>

<script>
	import {changeRole} from '@/api/common'
	import {getComOrUserInfo} from "@/api/companyInterface/user.js"
	export default {
		data() {
			return {
				userInfo:{}
			}
		},
		onLoad(e) {
			this.getAuthInfo()
		},
		methods: {
			getAuthInfo(){
				getComOrUserInfo().then(res=>{
					this.userInfo=res.result.xflinggongOddUserInfoVo
				})
			},
			companyChange(){
			
				if (this.userInfo.isAuthCompany == '1') {
					this.$refs.tipModal.open({
						content: "确认切换身份为企业角色吗？",
						btnText: "切换",
						showCancel: true,
						success: function() {
							changeRole({
								authenticationType: "1"
							}).then(res => {
								uni.showToast({
									icon: 'none',
									title: "已成功切换企业角色",
									duration: 2000
								})
								setTimeout(() => {
									uni.switchTab({
										url: "/pages/companyPage/my/index"
									})
								})
							})
						}
					})
				
				} else {
					if(this.userInfo.checkStatus==='0'||this.userInfo.checkStatus===0){
						uni.navigateTo({
							url:`/pages/common/waitSh/index?rzType=${this.rzType}`
						})
					}else{
						this.$refs.tipModal.open({
							content: "您的企业角色还未认证,请先认证？",
							btnText: "去认证",
							showCancel: true,
							success: function() {
								uni.navigateTo({
									url:"/pages/companyPage/subpackge/rz/qyrz?rzType=qyqh"
								})
							}
						})
					}
				
				}
				
			},
			personChange() {
				if (this.userInfo.isAuthPersonal == '1') {
					this.$refs.tipModal.open({
						content: "确认切换身份为个人角色吗？",
						btnText: "切换",
						showCancel: true,
						success: function() {
							changeRole({
								authenticationType: "2"
							}).then(res => {
								uni.showToast({
									icon: 'none',
									title: "已成功切换个人角色",
									duration: 2000
								})
								setTimeout(() => {
									uni.switchTab({
										url: "/pages/companyPage/my/index"
									})
								})
							})
						}
					})

				} else {
					this.$refs.tipModal.open({
						content: "您的个人角色还未认证,请先认证？",
						btnText: "去认证",
						showCancel: true,
						success: function() {
							uni.navigateTo({
								url:"/pages/companyPage/subpackge/rz/grrz"
							})
						}
					})
				}
				
			}
		}
	}
</script>

<style>
	page {
		min-height: 100%;
		background: linear-gradient(0deg, #F8FAFF, #EBF0FF);
	}
</style>
<style scoped lang="scss"></style>